import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import "./plugins/element";
import "./utils/aplusJS";
import store from "./store/index";
// import "./utils/zwjsbridge.js";
import http from "./../http";
import md5 from "js-md5";
import mgopfn from "./utils/mgopFn.js";
import localStore from "./utils/localstorage.js";
import "../src/assets/global/css/global.css";
import "./utils/window";
export default Window;

Vue.use(localStore);

// import $ from jquery;
Vue.use(http);

Vue.prototype.$md5 = md5;

Vue.prototype.mgopfn = mgopfn;

import axios from "axios";
// 设置拦截器
axios.interceptors.request.use((config) => {
  // console.log(config);
  NProgress.start();
  config.headers.Authorization = window.sessionStorage.getItem("token");
  // 在最后必须return config
  return config;
});

axios.interceptors.request.use((config) => {
  NProgress.done();
  return config;
});

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title;
  } else {
    document.title = "爱阅之城";
  }
  next();

  const sUserAgent = window.navigator.userAgent.toLowerCase();
  const bIsDtDreamApp = sUserAgent.indexOf("dtdreamweb") > -1; // 浙里办APP
  const bIsAlipayMini =
    sUserAgent.indexOf("miniprogram") > -1 && sUserAgent.indexOf("alipay") > -1;
  if (bIsAlipayMini) {
    window.location.href =
      "https://puser.zjzwfw.gov.cn/sso/mobile.do?action=oauth&scope=1&servicecode=ayzctctsgxxt&goto=https://mapi.zjzwfw.gov.cn/web/mgop/gov-open/zj/2001886320/reserved/index.html";
    // next();
  } else {
    window.location.href =
      "https://puser.zjzwfw.gov.cn/sso/mobile.do?action=oauth&scope=1&servicecode=ayzctctsgxxt&goto=https://mapi.zjzwfw.gov.cn/web/mgop/gov-open/zj/2001886320/reserved/index.html";
  }


  var that = this;
  window.addEventListener(
    "pageshow",
    function(event) {
      if (
        event.persisted ||
        (window.performance && window.performance.navigation.type == 2)
      ) {
        ZWJSBridge.close() //这个是浙里办内部的api，调用close()接口关闭通过openLink打开的页面
          .then((result) => {
            console.log(result);
          })
          .catch((error) => {
            console.log(error);
          });
      }
      that.isLoad();
    },
    false
  );
});

Vue.config.productionTip = false;

new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount("#app");
